public class 盛最多水的容器 {
    
    public static void main(String[] args) {
        

        System.out.println(""+maxArea(new int[]{1,8,6,2,5,4,8,3,7}));

    }

    public static int maxArea(int[] height) {

        if(null==height || height.length <1) return 0;
        
        int maxArea = 0;
        int left = 0;
        int right = height.length - 1;

        while (left < right) {
            
            //当前面积
            int curArea = (right - left) * Math.min(height[left], height[right]);

            maxArea = Math.max(maxArea, curArea);

            if(height[left] <= height[right]){

                left ++;
            } else {

                right --;
            }
        }

        return maxArea;
    }
}
